package org.goyo.main.domain.dao.base.impl;

import org.apache.commons.lang.StringUtils;
import org.goyo.common.exception.DBException;
import org.goyo.common.utils.Pager;
import org.goyo.main.domain.dao.BaseDAO;
import org.goyo.main.domain.dao.base.ICategoriesDao;
import org.goyo.main.domain.entity.base.Categories;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CategoriesDaoImpl extends BaseDAO implements ICategoriesDao {

  @Override
  public Pager findByCond(String cond, Pager pager) throws DBException {
    StringBuffer buf = new StringBuffer("from Categories where 1=1 ");
    if (StringUtils.isNotBlank(cond)) {
      buf.append(" and ");
      buf.append(cond);
    }
    String hql = this.addSort(buf, pager);
    String countHql = "select count(*) " + buf.toString();
    return this.findObjectsByPager(hql, countHql, pager);
  }

  @Override
  public List<Categories> getAllCategories() throws DBException {
    StringBuffer buf = new StringBuffer("from Categories where 1=1 order by number");
    return this.findObjects(buf.toString(), null, null);
}

}
